#include "courier_savestg.h"
#include "ui_courier_savestg.h"

Courier_savestg::Courier_savestg(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Courier_savestg)
{
    ui->setupUi(this);
    this->setFixedSize(440,720);
    socket = SocketManager::getinstance().socket();
    addbottontovect();

    for(int i=0;i<10;i++){
        qDebug()<<i<<".....";
        connect(buttons.at(i),&QPushButton::clicked,this,[this,i](){
            sendRig sm;
            sm.type =7;
            sm.IC = i+1;
            strcpy(sm.ID,uid_stg.toUtf8());
//            strcpy(sm.Account,ivit_stg.toUtf8());
            QByteArray arr;
            arr.append((char*)&sm,sizeof (sendRig));
            socket->write(arr);

            emit(finish_save());
        });
    }
}

Courier_savestg::~Courier_savestg()
{
    delete ui;
}

void Courier_savestg::getstgstate(int *num,QString data)
{
    for(int i=0;i<10;i++){
        this->stgstate[i] = num[i];
        if(stgstate[i]==1){
            buttons.at(i)->setStyleSheet("background-color: rgb(255, 0, 0);");
            buttons.at(i)->setDisabled(true);
        }else{

            buttons.at(i)->setStyleSheet("background-color: rgb(0, 255, 0);");
        }
    }
    uid_stg = data;
}

void Courier_savestg::addbottontovect()
{
    buttons.append(ui->pushButton);
    buttons.append(ui->pushButton_2);
    buttons.append(ui->pushButton_3);
    buttons.append(ui->pushButton_4);
    buttons.append(ui->pushButton_5);
    buttons.append(ui->pushButton_6);
    buttons.append(ui->pushButton_7);
    buttons.append(ui->pushButton_8);
    buttons.append(ui->pushButton_9);
    buttons.append(ui->pushButton_10);
}
